package com.imchen.cms.cmscore.service;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.imchen.cms.cmscore.model.User;
import com.imchen.cms.constant.CMS;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author imchen
 * @create: 2019-01-14 06:35
 **/
@Service
public class TokenService {

    public  String getToken(User user) {
        String token = "";
        token = JWT.create().withAudience(user.getId().toString())
                .withExpiresAt(new Date(System.currentTimeMillis()+ CMS.TOKEN_EXPIRE_TIME))
                .withIssuer("imc")
                .withSubject("lavande")
                .sign(Algorithm.HMAC256(user.getPassword()));
        return token;
    }

}
